package cn.edu.nuc.onlinestore.stream;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;
//对文件流操作实现泛型
public class ObjectStream {
	public static boolean write(String path,Serializable obj){
		try(
				FileOutputStream fos=new FileOutputStream(path);
				ObjectOutputStream oos=new ObjectOutputStream(fos);){
			oos.writeObject(obj);
			return true;
		}catch(Exception e){
			e.getStackTrace();
		}
		return false;
	}
	@SuppressWarnings("unchecked")
	public static <T extends Serializable> T read(Class<T> classs,String path){
		try(
				FileInputStream fis=new FileInputStream(path);
				ObjectInputStream ois=new ObjectInputStream(fis);){
			return (T)ois.readObject();
		}catch(Exception e){
			e.printStackTrace();
		}
		return null;
	}
}
